<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>流程管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">流程名称</div>
                <div class="field">
                    <input name="procDefName" id="procDefName" type="text" class="ui-textbox" value="" validate="{required:true,maxlength:50}">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" class="sq-button sq-button-round">清空</span>
               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
               <span id="syncBtn" class="sq-button sq-button-round">同步数据</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<!-- 设置流程编号窗口-->
<div id="div_flow_setting_proc_id" style="display:none">
	<form id="div_flow_setting_proc_form_id">
            <div class="fieldset1 tabel_col clearFix">
			    <div class="fieldBox col_1_100">
			         <div class="label">流程编号标识</div>
			         <div class="field">
			              <input name="procNo" id="procNo" type="text" class="ui-textbox" value="">
			              <span class="requiredSymbol">*</span>
			         </div>
			   </div>
			 </div>
    </form>
</div>

<script type="text/javascript">
	var grid = null;
	$(function () {
		
		$("#div_flow_setting_proc_form_id").ligerForm({
        	 validate: true
 		});
		
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/system/sysflowmanage/initList.do',
	    	method : 'get',
	        columns: [
		            {
		                display: '序号',
		                width: 40,
		                render: function (rowdata, rowindex, value) {
		                    var h=rowindex+1;
		                    return h;
		                }
	            	}, {
	                    display: '流程名称',
	                    name: 'procDefName',
	                    minWidth: 100	
	                }, {
	                    display: '版本数量',
	                    name: 'procDefVersNum',
	                    width: 60
	                }, {
	                    display: '启用版本名称',
	                    name: 'useVersNm',
	                    minWidth: 100,
	                }, {
	                    display: '流程编号标识  <span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="说明:&#10;"></span>',
	                    name: 'procNo',
	                    minWidth: 100,
	                }, {
	                    display: '流程状态',
	                    name: 'isValidNm',
	                    width: 80,
	                    render: function (rowdata, rowindex, value) {
	                    	if(rowdata.isValid == 1){
	                    		return LogUtils.LOG_CMM_GRID_BTN_ENABLE;
	                    	}else if(rowdata.isValid == 0){
	                    		return LogUtils.LOG_CMM_GRID_BTN_DISABLE;
	                    	}
	                    }
	                }, {
	                    display: '配置',
	                    minWidth: 100,
	                    render: function (rowdata, rowindex, value) {
	                        var h;
	                        var h1='<a class="sq-button-hasicon" href="javascript:;" onclick="disableFlow(event';
	                            h1+=",'"+rowdata.id+"'";
	                            h1+=",'ligergrid1'";
	                            h1+=")\"><i class=\"sqBtnIco_13\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DISABLE+"</a>";
	                            
	                        var h2='<a class="sq-button-hasicon" href="javascript:;" onclick="enableFlow(event';
	                            h2+=",'"+rowdata.id+"'";
	                            h2+=",'ligergrid1'";
	                            h2+=")\"><i class=\"sqBtnIco_12\"></i>"+LogUtils.LOG_CMM_GRID_BTN_ENABLE+"</a>";
	                       
	                       /* var other='&nbsp;&nbsp;&nbsp;&nbsp;<a class="sq-button-hasicon" href="javascript:;" onclick="settingFlow(event';
		                       other+=",'"+rowdata.id+"','"+rowdata.procDefKey+"'";
		                       other+=",'ligergrid1'";
		                       other+=")\"><i class=\"sqBtnIco_40\"></i>"+LogUtils.LOG_FLOW_GRID_BTN_SETTING+"</a>";
	                            */
	                        var other= "";
	                           other+='&nbsp;&nbsp;&nbsp;&nbsp;<a class="sq-button-hasicon" href="javascript:;" onclick="historyFlow(event';
	                           other+=",'"+rowdata.id+"'";
	                           other+=",'ligergrid1'";
	                           other+=")\"><i class=\"sqBtnIco_41\"></i>"+LogUtils.LOG_FLOW_GRID_BTN_HISTORY+"</a>";
	                         
	                           other+='&nbsp;&nbsp;&nbsp;&nbsp;<a class="sq-button-hasicon" href="javascript:;" onclick="settingProcNo(event';
	                           other+=",'"+rowdata.id+"'";
	                           other+=",'"+rowdata.procNo+"'";
	                           other+=",'ligergrid1'";
	                           other+=")\"><i class=\"sqBtnIco_42\"></i>"+LogUtils.LOG_FLOW_GRID_BTN_SETTING_PROCNO+"</a>";
	                            
	                           
	                        switch (rowdata.isValid){
	                            case 0:
	                                h=h2;
	                                break;
	                            case 1:
	                                h=h1;
	                                break;
	                            default:
	                            	h=h1;
	                            	break;
	                        }
	                        return h + other;
	                    }
	                } 
	            
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        rownumbers:false/* ,
	        onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	    //赋值Grid
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    //初始查询form
	    $("#searchBar").ligerForm();
		//查询按钮
	    $("#searchBtn").click(function(event) {
	    	reloadGrid();
	    });
		
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	    });
	    
	    //同步工作流引擎数据
	    $("#syncBtn").click(function(event) {
	    	var _url = '<%=path%>/flow/flow/syncFlowDefDataFromRemote.do';
	    	AjaxUtils.ajaxPost(_url, {}, function(msg){
	    		if(msg.success == 1){
	   				 UIUtils.alertSuccess(msg.info);
	   				 reloadGrid();
	   			 }else{
	   				 UIUtils.alertError(msg.info);
	   			 }
	    	 },true);
	    });
	});
	
	//带条件重载Grid
	function reloadGrid(){
		 var form = new liger.get("searchBar");
         var data = form.getData();
         //alert(JSON.stringify(data));
         for (name in data){
            grid.setParm(name,data[name]);
         };
         grid.reload();
	}
	
	//历史版本设置
	function historyFlow(event, _id, grid){
		$.ligerDialog.SQopen({
            width: 850,
            height:480,
            title : '历史版本',
            url:'<%=path%>/system/sysflowmanagev/toListPage.do?manageId='+_id
        });
	}
	
	//设置流程
	function settingFlow(event, _id, _procDefKey, grid){
		$.ligerDialog.SQopen({
            width: 400,
            height:600,
            title : '关联组织机构',
            url:'<%=path%>/system/sysflowmanageorgr/toListPage.do?manageId='+_id+"&procDefKey="+_procDefKey
        });
	}
	
	//禁用数据
	function disableFlow(event, _id, grid){
		var parms = {
    			id:_id
    	}
		var _url = '<%=path%>/system/sysflowmanage/modifyDisableFlow.do';
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
			if(flag == false)return;
			AjaxUtils.ajaxPost(_url, parms, function(msg){
				 if(msg.success == 1){
   					 UIUtils.alertSuccess(msg.info);
   				 	 reloadGrid();
	   			 }else{
	   				 UIUtils.alertError(msg.info);
	   			 }
	    	 },true);
			
		});
	}
	
	//启用流程
	function enableFlow(event, _id, grid){
		var parms = {
    			id:_id
    	}
    	var _url = '<%=path%>/system/sysflowmanage/modifyEnableFlow.do';
    	AjaxUtils.ajaxPost(_url, parms, function(msg){
    		if(msg.success == 1){
				 UIUtils.alertSuccess(msg.info);
				 reloadGrid();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
   	 	},true);
    	
	}
	
	//设置流程编号
	function settingProcNo(event,_id, _procNo){
		if(StringUtils.isNotEmpty(_procNo)){
			if(_procNo == "null"){
				_procNo = "";
			}
			$("#procNo").val(_procNo);//赋值原有值
		}else{
			$("#procNo").val("");//弹出清空	
		}
		
        $.ligerDialog.SQopen({
            width: 400,
            title : '设置',
            target: $("#div_flow_setting_proc_id"),
            buttons: [
                      {
                          text: "保存", cls: 'l-dialog-btn-ok', onclick:function(){
                        	 modifyProcNo(_id);
                          }
                      }, {
                          text: "取消", cls: 'l-dialog-btn-no', onclick:function(){
                          	$.ligerDialog.hide();
                          }
                      }
                  ]

        });
	}
	
	//修改流程编号
    function modifyProcNo(_id){
    	 var ligerForm = liger.get("div_flow_setting_proc_form_id");
         if (!ligerForm.valid()) {
             UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
             return false; //验证不通过，不执行以下代码
         }
    	 var data = ligerForm.getData();
    	 var _url = "<%=path%>/system/sysflowmanage/modifyProcNo.do";
    	 data["id"] = _id;
    	 AjaxUtils.ajaxPost(_url, data, function(msg){
    		 if(msg.success == 1){
    			$.ligerDialog.hide();
    	    	UIUtils.alertSuccess(msg.info);
    	    	reloadGrid();
    		 }else{
    			UIUtils.alertError(msg.info);
    		 }
    	 },true);
    }
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
</script>
</body>
</html>